<template>
	<scroll-view @scrolltolower="handleScrollToLower" class="sw" scroll-y :lower-threshold="300">
		<view class="list">
			<view class="" v-for="(item,index) in tabList" class="li" :key="index" @click="buitem(item)">
				<image :src="item.images" class="goods"></image>
				<view class="name">{{item.goodName}}</view>
				<view class="fen">
					<text class="red">{{item.points}}</text>
					<text class="red_name">积分</text>
				</view>
			</view>

			<u-popup :show="show" @close="close" @open="open" mode="bottom" :closeable="true" round="10">
				<view class="box">
					<view class="title">商品介绍</view>
					<view class="dis aic jcsb">
						<view>
							<image :src="selectedItem.images" class="goods_img"></image>
						</view>
						<view class="">
							<view class="good_name">{{selectedItem.goodName}}</view>
							<view class="good_fen">
								<text class="red">{{selectedItem.points}}</text>
								<text class="red_name">积分</text>
							</view>
						</view>
					</view>
					<view class=" " style="margin-top: 60rpx;">
						<view class="miaosu">
							商品描述
						</view>
						<view class="box">
							<u-parse :content="selectedItem.description"></u-parse>
						</view>
					</view>
					<view class="save" @click="goConfirmOrder">确认兑换</view>
				</view>
			</u-popup>
		</view>
	</scroll-view>
</template>

<script>
	import {
		pointsGoodsList
	} from "@/api.js"
	export default {
		data() {
			return {
				show: false,
				pageNo: 1,
				pageSize: 10,
				total: 0,
				tabList: [],
				selectedItem: {}
			}
		},
		onLoad(options) {
			console.log('options', options);
			this.init()
		},
		methods: {
			init() {
				this.getList()
			},
			handleScrollToLower() {
				let pageNo = this.pageNo
				let pageSize = this.pageSize
				let total = this.total
				console.log('一共' + total + '条，当前已经加载' + pageSize * pageNo + '条');
				if (total <= pageNo * pageSize) {
					console.log('已经到底了');
					return
				}
				uni.showLoading({
					title: '加载中'
				});
				this.pageNo++;
				this.getList();
				uni.hideLoading();
			},
			async getList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				let res = await pointsGoodsList({
					pageNo: this.pageNo,
					pageSize: this.pageSize,
				})
				this.tabList = this.tabList.concat(res.result.records)
				this.total = res.result.total

				uni.hideLoading();

			},
			buitem(item) {
				this.show = true
				this.selectedItem = item
			},
			close() {
				this.show = false
			},
			goConfirmOrder() {
				uni.navigateTo({
					url: "/pages/shop/confirmOrder?id=" + this.selectedItem.id
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.sw {
		height: 100vh;
	}

	.list {
		width: calc(750rpx - 28rpx - 28rpx);
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		margin: 0 auto;

		.li {
			width: 320rpx;
			height: 470rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(187, 187, 187, 0.15);
			border-radius: 11rpx 11rpx 11rpx 11rpx;
			margin: 10rpx 12rpx;

			.goods {
				width: 325rpx;
				height: 280rpx;
				border-radius: 11rpx 11rpx 0rpx 0rpx;
			}

			.name {
				font-family: Roboto Mono, Roboto Mono;
				font-weight: 300;
				font-size: 23rpx;
				color: #000000;
				padding: 0 14rpx;
				margin-top: 40rpx;
			}

			.fen {
				padding: 0 14rpx;
				margin-top: 30rpx;

				.red {

					font-family: Roboto, Roboto;
					font-weight: 500;
					font-size: 35rpx;
					color: #FF7373;
				}

				.red_name {
					font-family: Roboto, Roboto;
					font-weight: 500;
					font-size: 18rpx;
					color: rgba(0, 0, 0, 0.76);
				}
			}


		}
	}

	.box {
		width: 750rpx;
		height: 1150rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		position: relative;

		.title {
			font-family: Roboto, Roboto;
			font-weight: 500;
			font-size: 36rpx;
			color: #000000;
			text-align: center;
			margin-top: 40rpx;
			margin-bottom: 40rpx;
		}

		.goods_img {
			width: 283rpx;
			height: 175rpx;
			margin-right: 30rpx;
		}

		.good_name {
			font-family: Roboto Mono, Roboto Mono;
			font-weight: 300;
			font-size: 32rpx;
			color: #000000;
		}

		.good_fen {
			text-align: right;
		}

		.miaosu {
			font-family: Roboto, Roboto;
			font-weight: 500;
			font-size: 25rpx;
			color: #656565;
			margin-right: 45rpx;
		}

		.lk {
			font-family: Roboto, Roboto;
			font-weight: 500;
			font-size: 25rpx;
			color: rgba(0, 0, 0, 0.89);
			line-height: 34rpx;
		}

		.red {

			font-family: Roboto, Roboto;
			font-weight: 500;
			font-size: 35rpx;
			color: #FF7373;
		}

		.red_name {
			font-family: Roboto, Roboto;
			font-weight: 500;
			font-size: 18rpx;
			color: rgba(0, 0, 0, 0.76);
		}

		.save {
			width: 480rpx;
			height: 90rpx;
			line-height: 90rpx;
			background: #F6D44D;
			border-radius: 1805rpx 1805rpx 1805rpx 1805rpx;
			font-family: Roboto, Roboto;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			text-align: center;
			margin: 0 auto;
			position: absolute;
			bottom: 50rpx;
			left: 135rpx;
		}
	}

	.box {
		width: 690rpx;

	}
</style>